//
// Created by cljh on 2023/3/28.
//

#ifndef BIN_PACKING_NESTPATH_H
#define BIN_PACKING_NESTPATH_H

#include <vector>
#include "Polygon.h"

//同类型的一系列图形（如某nfp可能由多个图形构成）
class NestPath{
public:
    std::vector<Polygon*> polygons;
    int id;//底板id=0,其他的从1开始
    int rotation;
    double area;
    std::string name;
    NestPath(){
        polygons=std::vector<Polygon*>();
        id=-1;
        rotation=0;
        area=-1;
        name = "";
    }
    NestPath(std::vector<Polygon*> _polygons,int _id,int _rotation){
        polygons=_polygons;
        id=_id;
        rotation=_rotation;
        area=-1;
        name = "";
    }
    int size(){
        return polygons.size();
    }
    Polygon* operator [](int i){
        return polygons[i];
    }
    Polygon* operator [](int i) const{
        return polygons[i];
    }
    void push_back(Polygon *p){
        polygons.push_back(p);
    }

    // 将 NestPath 转换为 QPainterPath
    QPainterPath toQPainterPath() {
        QPainterPath path;
        for (int i = 0; i < polygons.size(); ++i) {
            if (i == 0) {
                path.addPolygon(polygons[i]->toQPolygonF());
            } else {
                // 对于孔洞路径，我们需要确保其方向为顺时针
//                path = path.subtracted();
            }
        }
        return path;
    }

    void selfDelete(){
        for(int i=0;i<polygons.size();i++){
            delete polygons[i];
            polygons[i]= nullptr;
        }
        polygons.clear();
    }
};



#endif //BIN_PACKING_NESTPATH_H
